package BackOffice;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Kategorie_Sprache_Bearbeiten extends javax.swing.JPanel {
	private JTextField sprache_kuerzel;
	private JLabel kuerzel;
	private JSeparator jSeparator1;
	private JLabel jKategorie;
	private JLabel jsprache;
	private JComboBox jkategorie_entfernen;
	private JComboBox jsprache_entf;
	private JButton kategorie_entfernen;
	private JLabel bezeichnung;
	private JButton hauptmenue;
	private JButton Exit;
	private JButton kategorie_Hinzufuegen;
	private JLabel JKategorie;
	private JTextField Kategorie;
	private JLabel LSprache;
	private JComboBox sprachen;
	private JLabel text;
	private JButton SP_hinzufuegen;
	private JTextField sprache_bezeichnung;

	/**
	 * Auto-generated main method to display this JPanel inside a new JFrame.
	 */
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new Kategorie_Sprache_Bearbeiten());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}

	public Kategorie_Sprache_Bearbeiten() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			this.setPreferredSize(new java.awt.Dimension(800, 600));
			this.setLayout(null);
			{
				sprache_kuerzel = new JTextField();
				sprache_kuerzel.setLayout(null);
				this.add(sprache_kuerzel);
				sprache_kuerzel.setBounds(393, 64, 133, 25);
			}
			{
				kuerzel = new JLabel();
				this.add(kuerzel);
				kuerzel.setText("K\u00FCrzel");
				kuerzel.setBounds(293, 68, 63, 16);
			}
			{
				sprache_bezeichnung = new JTextField();
				this.add(sprache_bezeichnung);
				sprache_bezeichnung.setBounds(393, 111, 133, 25);
			}
			{
				bezeichnung = new JLabel();
				this.add(bezeichnung);
				bezeichnung.setText("Bezeichnung");
				bezeichnung.setBounds(293, 113, 89, 16);
			}
			{
				SP_hinzufuegen = new JButton();
				this.add(SP_hinzufuegen);
				SP_hinzufuegen.setText("Sprache Hinzuf\u00FCgen");
				SP_hinzufuegen.setBounds(350, 172, 163, 45);
				SP_hinzufuegen.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						SP_hinzufuegenActionPerformed(evt);
					}
				});
			}
			{
				text = new JLabel();
				this.add(text);
				text.setBounds(344, 472, 190, 30);
			}
			{
				ComboBoxModel sprachenModel = new DefaultComboBoxModel();
				sprachen = new JComboBox();
				this.add(sprachen);
				sprachen.setModel(sprachenModel);
				sprachen.setBounds(131, 65, 133, 23);
			}
			{
				LSprache = new JLabel();
				this.add(LSprache);
				LSprache.setText("Sprache");
				LSprache.setBounds(11, 68, 84, 16);
			}
			{
				Kategorie = new JTextField();
				this.add(Kategorie);
				Kategorie.setBounds(131, 113, 133, 25);
			}
			{
				JKategorie = new JLabel();
				this.add(JKategorie);
				JKategorie.setText("Kategorie");
				JKategorie.setBounds(11, 117, 102, 16);
			}
			{
				kategorie_Hinzufuegen = new JButton();
				this.add(kategorie_Hinzufuegen);
				kategorie_Hinzufuegen.setText("Kategorie Hinzuf\u00FCgen");
				kategorie_Hinzufuegen.setBounds(93, 172, 171, 45);
				kategorie_Hinzufuegen.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						kategorie_HinzufuegenActionPerformed(evt);
					}
				});
			}
			{
				Exit = new JButton();
				this.add(Exit);
				Exit.setText("Exit");
				Exit.setBounds(575, 307, 136, 69);
				Exit.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ExitActionPerformed(evt);
					}
				});
			}
			{
				hauptmenue = new JButton();
				this.add(hauptmenue);
				hauptmenue.setText("Hauptmen\u00FC");
				hauptmenue.setBounds(126, 307, 140, 68);
				hauptmenue.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						hauptmenueActionPerformed(evt);
					}
				});
			}
			{
				kategorie_entfernen = new JButton();
				this.add(kategorie_entfernen);
				kategorie_entfernen.setText("Kategorie entfernen");
				kategorie_entfernen.setBounds(592, 172, 176, 45);
				kategorie_entfernen.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						kategorie_entfernenActionPerformed(evt);
					}
				});
			}
			{
				ComboBoxModel jsprache_entfModel = new DefaultComboBoxModel();
				jsprache_entf = new JComboBox();
				this.add(jsprache_entf);
				jsprache_entf.setModel(jsprache_entfModel);
				jsprache_entf.setBounds(636, 65, 132, 23);
				jsprache_entf.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jsprache_entfActionPerformed(evt);
					}
				});
			}
			{
				ComboBoxModel jkategorie_entfernenModel = new DefaultComboBoxModel();
				jkategorie_entfernen = new JComboBox();
				this.add(jkategorie_entfernen);
				jkategorie_entfernen.setModel(jkategorie_entfernenModel);
				jkategorie_entfernen.setBounds(636, 110, 132, 23);
			}
			{
				jsprache = new JLabel();
				this.add(jsprache);
				jsprache.setText("Sprache");
				jsprache.setBounds(538, 69, 84, 16);
			}
			{
				jKategorie = new JLabel();
				this.add(jKategorie);
				jKategorie.setText("Kategorie");
				jKategorie.setBounds(538, 110, 92, 16);
			}
			{
				jSeparator1 = new JSeparator();
				this.add(jSeparator1);
				jSeparator1.setBounds(98, 271, 635, 12);
			}
			combofuellen();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void SP_hinzufuegenActionPerformed(ActionEvent evt) {
		if (!sprache_kuerzel.getText().isEmpty()) {
			if (!sprache_bezeichnung.getText().isEmpty()) {
				if (Statements.sprachehinzufuegen(sprache_kuerzel.getText(),
						sprache_bezeichnung.getText())) {
					text.setText("Sprache Hinzugefuegt");
				} else
					text.setText("Sprache existiert schon");
				combofuellen();
			}
		} else
			text.setText("Felder Leer");
		try {
			Statements.conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Statements.conn = null;
		try {
			Statements.stmt.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Statements.stmt = null;
	}

	private void combofuellen() {
		sprachen.removeAllItems();
		jsprache_entf.removeAllItems();
		//ResultSet tmp = Statements.combosprachefuellen();
		Statements.combosprachefuellen(sprachen);
		Statements.combosprachefuellen(jsprache_entf);
		combokategoriefuellen();

	}

	private void combokategoriefuellen() {
		if (jsprache_entf.getSelectedItem() != null) {
			jkategorie_entfernen.removeAllItems();
			Statements.combokategoriefuellen(jsprache_entf
					.getSelectedItem().toString(), jkategorie_entfernen);

		}
	}

	private void kategorie_HinzufuegenActionPerformed(ActionEvent evt) {
		if (!Kategorie.getText().isEmpty()) {
			if (Statements.kategorie_hinzufuegen(sprachen.getSelectedItem()
					.toString(), Kategorie.getText())) {
				text.setText("Kategorie Hinzufeg\u00FCgt");
			} else
				text.setText("Kategorie nicht Hinzufeg\u00FCgt");
		} else {
			text.setText("Feld Leer");
		}
		combokategoriefuellen();
	}

	private void ExitActionPerformed(ActionEvent evt) {
		System.exit(0);
	}

	private void hauptmenueActionPerformed(ActionEvent evt) {
		Start.getStart().getContentPane().removeAll();
		Hauptmenue H = new Hauptmenue();
		Start.getStart().add(H);
		Start.getStart().validate();
	}

	private void kategorie_entfernenActionPerformed(ActionEvent evt) {
		Statements.kategorie_loschen(jkategorie_entfernen.getSelectedItem()
				.toString(), jsprache_entf.getSelectedItem().toString());
		combokategoriefuellen();

	}

	private void jsprache_entfActionPerformed(ActionEvent evt) {
		combokategoriefuellen();
	}
}
